<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragment::head(~{::title})">
    <meta charset="UTF-8">
    <meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <title th:text="${blog.title}">博客详情</title>
    <link href="../static/css/semantic.min.css" rel="stylesheet">
    <link href="../static/css/style.css" rel="stylesheet">
    <link href="../static/lib/prism/prism.css" rel="stylesheet">
    <link href="../static/lib/typo/typo.css" rel="stylesheet">
    <link href="../static/lib/tocbot/tocbot.css" rel="stylesheet">
</head>
<body>
<!--导航 -->
<nav th:replace="_fragment::menu(0)" class="ui inverted attached segment m-padding-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">我的博客</h2>
            <a href="#" class="m-item item m-mobile-hide"><i class="home mini icon"></i>首页</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="idea mini icon"></i>分类</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="tags mini icon"></i>标签</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="clone mini icon"></i>归档</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="info mini icon"></i>关于我</a>
            <div class="right m-item item m-mobile-hide">
                <div class="ui transparent inverted icon input">
                    <input type="text" placeholder="Search...">
                    <i class="search link icon"></i>
                </div>
            </div>
        </div>
    </div>
    <div class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </div>
</nav>

<!-- 中间内容 -->
<div class="m-container-small m-padding-tb-small m-container-height">
    <div class="ui container">
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <div class="item">
                    <img src="../static/images/girl.jpeg" th:src="${blog.user.avatar}" alt="" class="ui avatar image">
                    <div class="content"><a href="#" th:href="@{/about}" class="header" th:text="${blog.user.nickname}">彭阳宴</a></div>
                </div>
                <div class="item">
                    <i class="calendar icon"></i> <span th:text="${#dates.format(blog.updateTime,'YYYY-MM-dd HH:mm')}">2020-03-09</span>
                </div>
                <div class="item">
                    <i class="eye icon"></i> <span th:text="${blog.views}">200</span>
                </div>
            </div>
        </div>
        <!-- 图片区域 -->
        <div class="ui attached segment">
            <img src="../static/images/girl.jpeg" th:src="${blog.firstPicture}" alt="" class="ui fluid rounded image" style="max-height: 400px">
        </div>
        <!--内容 -->
        <div class="ui attached padded segment">
            <div class="ui right aligned basic segment">
                <div class="ui orange basic label" th:text="${blog.flag}">原创</div>
            </div>
            <h2 class="ui center aligned header" th:text="${blog.title}"> 关于放屁不愁 </h2>
            <div id="content" class="typo typo-selection js-toc-content m-padding-lr-responsive m-padding-tb-big" th:utext="${blog.content}">
            </div>
            <!-- 标签 -->
            <div class="m-padding-lr-responsive">
                <div class="ui basic teal left pointing label" th:text="${blog.type.name}">方法论</div>
            </div>
            <!--赞赏 -->
            <div class="ui basic center aligned segment" th:if="${blog.appreciation}">
                <div class="ui circular orange button" id="payButton">赞赏</div>
            </div>
            <div class="ui payQR flowing popup transition hidden">
                <div class="ui orange basic label">
                    <div class="ui center aligned images" style="font-size: inherit !important;">
                        <div class="image">
                            <img src="../static/images/qr.jpg" th:src="${blog.user.payCodeUrl1}" alt="" class="ui rounded bordered image" style="width: 120px;">
                            <div>支付宝</div>
                        </div>
                        <div class="image">
                            <img src="../static/images/qr.jpg" th:src="${blog.user.payCodeUrl2}" alt="" class="ui rounded bordered image" style="width: 120px;">
                            <div>微信</div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!-- 博客信息 -->
        <div class="ui attached positive message" th:if="${blog.shareable}">
            <div class="ui middle aligned grid">
                <div class="eleven wide column">
                    <ul class="list">
                        <li>作者： <span th:text="${blog.user.nickname}"></span></li>
                        <li>发表时间： <span th:text="${blog.updateTime}"></span></li>
                        <li>版权声明： 自由转载-非商用-非衍生-保持署名 （创意共享3.0许可证）</li>
                        <li>公众号转载： 请再文末添加作者公众号二维码</li>
                    </ul>
                </div>
                <div class="five wide column">
                    <img src="../static/images/qr.jpg" th:src="${blog.user.wechatQRCode}" alt="" class="ui right floated rounded bordered image" style="width: 120px;">
                </div>
            </div>
        </div>
        <!-- 留言区域 -->
        <div class="ui bottom attached segment" th:if="${blog.commentable}">
            <!-- 区域列表--->
            <div id="leave-words" class="ui teal segment">
                <div th:fragment="CommentList">
                    <div class="ui header">评论</div>
                    <span th:if="${comments.size()==0}">快来抢先第一个留言吧</span>
                    <div class="ui comments">
                        <div class="comment" th:each="comment:${comments}">
                            <a class="avatar">
                                <img src="../static/images/girl.jpeg" th:src="${comment.avatar}">
                            </a>
                            <div class="content">
                                <a class="author">
                                    <span th:text="${comment.nickname}">Matt</span>
                                    <span th:if="${comment.adminComment}" class="ui mini basic teal left pointing label m-padding-mini">博主</span>
                                </a>
                                <div class="metadata">
                                    <span class="date" th:text="${#dates.format(comment.createTime,'yyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                </div>
                                <div class="text" th:text="${comment.content}">太赞了！ </div>
                                <div class="actions">
                                    <a class="reply" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" data-commentid="1" data-commentnickname="Jack" onclick="reply(this)">回复</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)>0}">
                                <div class="comment" th:each="reply:${comment.getReplyComments()}">
                                    <a class="avatar">
                                        <img src="../static/images/girl.jpeg" th:src="${reply.avatar}">
                                    </a>
                                    <div class="content">
                                        <span class="author">
                                            <span th:text="${reply.nickname}">小李</span>
                                            <span th:if="${reply.adminComment}" class="ui mini basic teal left pointing label m-padding-mini">博主</span>
                                        </span>
                                        <span th:text="|回复 ${reply.parentComment.getNickname()}|" style="color: teal;">@小米</span>
                                        <div class="metadata">
                                            <span class="date" th:text="${#dates.format(reply.createTime,'yyy-MM-dd HH:mm')}">刚刚</span>
                                        </div>
                                        <div class="text" th:text="${reply.content}">艾略特你永远是多么正确 :) </div>
                                        <div class="actions">
                                            <a class="reply" th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" data-commentid="1" data-commentnickname="Jack" onclick="reply(this)">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 留言区-->
            <div id="comment-form" class="ui form">
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="field">
                    <textarea name="content" placeholder="请输入评论信息..." cols="30" rows="10"></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名" th:value="${session.user}!=null?${session.user.nickname}:''">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="email" name="email" placeholder="邮箱" th:value="${session.user}!=null?${session.user.email}:''">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <button id="commentSubmit-btn" type="button" class="ui teal button m-mobile-wide"><i class="edit icon"></i>发布</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<div id="toolbar" class="ui vertical icon buttons m-fixed m-right-bottom">
    <button type="button" class="ui teal toc button">目录</button>
    <a href="#leave-words" class="ui teal button">留言</a>
    <button class="ui icon wechat button"><i class="weixin icon"></i></button>
    <button id="toTop-btn" class="ui icon button"><i class="chevron up icon"></i></button>
</div>

<!-- 博客目录 -->
<div class="ui toc-container flowing popup transition hidden" style="width: 250px">
    <span th:text="${blog.title}"></span>
    <ol class="js-toc"></ol>
</div>

<!-- 二维码 -->
<div class="ui wechat-qr flowing popup transition hidden m-padding-mini" style="width: 130px !important;">
    <div  id="qrcode" class="ui rounded image" style="padding: 5px!important;"></div>
</div>


<!-- 底部footer -->
<footer th:replace="_fragment::footer" class="ui inverted vertical segment m-margin-top-small">
    <div class="ui center aligned container">
        <div class="ui stackable inverted divided grid m-padding-tb-big">
            <div class="three wide column">
                <div class="ui item">
                    <img src="../static/images/girl.jpeg" alt="" class="ui rounded image m-inline-block" style="width: 100px;">
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事{ user story }</a>
                    <a href="#" class="item">用户故事{ user story }</a>
                    <a href="#" class="item">用户故事{ user story }</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事{ user story }</a>
                    <a href="#" class="item">用户故事{ user story }</a>
                    <a href="#" class="item">用户故事{ user story }</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced">最新博客</h4>
                <p class="m-text-thin m-text-spaced m-opacity-mini">xxxxxxxxxxxxxxxxxxxxx</p>
            </div>
        </div>
        <div class="ui inverted selection divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2020 - 2021 Mr.Peng</p>
    </div>
</footer>
<!--/*/<th:block th:replace="_fragment::script">/*/-->
<script src="../static/js/jquery.min.js"></script>
<script src="../static/js/semantic.min.js"></script>
<script src="../static/lib/prism/prism.js"></script>
<script src="../static/lib/tocbot/tocbot.min.js"></script>
<script src="../static/lib/qrcode/qrcode.js"></script>
<script src="../static/lib/toTop/jquery.toTop.min.js"></script>
<!--/*/</th:block>/*/-->
<script>
    $('.menu.toggle').click(function () {
      $('.m-item').toggleClass('m-mobile-hide')
    });
    $('#payButton').popup({
      popup: $('.payQR.popup'),
      on: 'click',
      position: 'bottom center'
    })
    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3, h4',
        // For headings inside relative or absolute positioned containers within content.
        hasInnerContainers: true,
    });
    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    })
    $(".wechat").popup({
        popup: $('.wechat-qr'),
        position: "left center"
    })
    var url = window.location.href;
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        text: url,
        width: 120,
        height: 120,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });
    $('#toTop-btn').click(function () {
        $('#toTop-btn').toTop({speed:500,autohide:false,position:false})
    })
    $(window).scroll(function () {
        var top = window.scrollY;
        if (top<20){
            $('#toolbar').hide()
        }else {
            $('#toolbar').show()
        }
    })

    //评论表的表单验证
    $('.ui.form').form({
        fields: {
            nickname: {
                identifier: 'nickname',
                rules:[{
                    type: 'empty',
                    prompt: '请输入昵称'
                }]
            },
            email: {
                identifier: 'email',
                rules:[{
                    type: 'empty',
                    prompt: '请输入正确的邮箱地址'
                }]
            },
            content: {
                identifier: 'content',
                rules:[{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }]
            }
        }
    });

    $("#commentSubmit-btn").click(function () {
        var boo = $('.ui.form').form('validate form');
        if (boo){
            postData()

        } else {
            console.log("表单验证不通过")
        }
    });
    
    function postData() {
        $("#leave-words").load("/comments",{
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id":$("[name='blog.id']").val(),
            "nickname":$("[name='nickname']").val(),
            "email":$("[name='email']").val(),
            "content":$("[name='content']").val()
        },function (reponseTxt, statusTxt, xhr) {
            clearContent();
        })
    }

    function clearContent() {
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").val('').attr("placeholder","请输入评论信息...");
    }

    function reply(obj) {
        var commentid = $(obj).data('commentid');
        var commentnickname = $(obj).data('commentnickname');
        $("[name='content']").attr("placeholder","@"+commentnickname).focus();
        $("[name='parentComment.id']").val(commentid);
        $(window).scrollTo("#comment-form",500);
    }

</script>
</body>
</html>